<?php
/**
 * 変換クラス convert.
 *
 * @date 2008/07/24
 * @author nagai
 * @version $Id: convert.php 27 2009-11-26 06:53:05Z tzr250rsp $
 */
class convert extends convert_base {

  /**
   * A recursive array_change_key_case function.
   * @param array $input
   * @param integer $case CASE_UPPER | CASE_LOWER
   */
  static public function arrayChangeKeyCaseRecursive($input, $case = null){
    /*CASE_UPPER*/

    if(!is_array($input)){
      trigger_error("Invalid input array '".$array."'",E_USER_NOTICE); exit;
    }
    // CASE_UPPER|CASE_LOWER
    if(null === $case){
      $case = CASE_LOWER;
    }
    if(!in_array($case, array(CASE_UPPER, CASE_LOWER))){
      trigger_error("Case parameter '".$case."' is invalid.", E_USER_NOTICE); exit;
    }
    $input = array_change_key_case($input, $case);
    foreach($input as $key=>$array){
      if(is_array($array)){
        $input[$key] = self::arrayChangeKeyCaseRecursive($array, $case);
      }
    }
    return $input;
  }


  /**
   * 文字コードを変換します.
   * 配列の場合は再帰的に処理します
   * @param mixed $str
   * @return mixed
   */
  static public function reflexive_encoding($string_array,$encod,$from_encoding=null){
    if(is_array($string_array)){
      foreach($string_array as $k => $v){
        $string_array[$k] = self::reflexive_encoding($v,$encod,$from_encoding);
      }
    }else{
      $string_array = parent::_encoding($string_array,$encod,$from_encoding);
    }
    return $string_array;
  }


  /**
   * SJISに変換します.
   * @param mixed $str
   */
  static public function encodingSjis($str){
    return self::reflexive_encoding($str,'SJIS');
  }


  /**
   * JISに変換します.
   * @param mixed $str
   */
  static public function encodingJis($str){
    return self::reflexive_encoding($str,'JIS');
  }


  /**
   * iso-2022-jpに変換します.
   * @param mixed $str
   */
  static public function encodingIso2022jp($str){
    return self::reflexive_encoding($str,'iso-2022-jp');
  }


  /**
   * sjis-winに変換します.
   * @param mixed $str
   */
  static public function encodingSjisWin($str){
    return self::reflexive_encoding($str,'SJIS-win');
  }


  /**
   * UTF-8に変換します.
   * @param mixed $str
   */
  static public function encodingUtf8($str){
    return self::reflexive_encoding($str,'UTF-8');
  }


  /**
   * SJIS-winからUTF-8に変換します.
   * @param mixed $str
   */
  static public function encodingUtf8FromSjisWin($str){
    return self::reflexive_encoding($str,'UTF-8','SJIS-win,SJIS,UTF-8');
  }


  /**
   * EUC-JPに変換します.
   * @param mixed $str
   */
  static public function encodingEuc($str){
    return self::reflexive_encoding($str,'EUC-JP');
  }


  /**
   * メールなどのheaderにマルチバイトを入れたい場合など.
   * mb_encode_mimeheader
   * @param mixed $str
   */
  static public function mbEncodeMimeheader($str){
    return mb_encode_mimeheader( mb_convert_encoding($str, 'JIS', 'auto'), 'iso-2022-jp');
  }


  /**
   * 全角カナを半角かなへ変換.
   * @param $str
   * @return string
   */
  static public function mbKanaTosbKana($str,$encoding='utf8' ){
    return mb_convert_kana($str, "k",$encoding);
  }


  /**
   * 半角かなを全角かなへ変換.
   * @param $str
   * @return string
   */
  static public function mbsbKanaToKana($str,$encoding='utf8' ){
    return mb_convert_kana($str, "K",$encoding);
  }


  /**
   * 全角英数を半角英数へ変換.
   * @param $str
   * @return string
   */
  static public function mbAlphabetsTosbAlphabets($str,$encoding='utf8' ){
    return mb_convert_kana($str, "a",$encoding);
  }


  /**
   * 半角英数を全角英数へ変換.
   * @param $str
   * @return string
   */
  static public function sbAlphabetsToMbAlphabets($str,$encoding='utf8' ){
    return mb_convert_kana($str, "A",$encoding);
  }


}
//end of class
?>